package com.objectdraw.server.tools;

import com.objectdraw.server.ObjectDrawServer;
import com.objectdraw.server.data.Action;


/**
 * Takes a mouse pressed event message when the selection tool is active and checks
 * to find an object to select.
 * 
 * @author cfruehan
 *
 */
public class SelectionServerTool extends ServerTool {
	private int x,y;
	
	/**
	 * if the action presented is a mouse pressed action then the server selects the top object
	 * with coords provided. If it is a mouse released action then the selected object is moved to the
	 * release point.
	 */
	@Override
	public void addAction(Action act) {
		if(act.getAction().equalsIgnoreCase("mouse")){
			String[] args=act.getArguments().split(" ");
			if(act.getEvent().equalsIgnoreCase("pressed")){
				x=Integer.parseInt(args[0]);
				y=Integer.parseInt(args[1]);
				ObjectDrawServer.getInstance().selectObject(x,y);
			}else if(act.getEvent().equalsIgnoreCase("released")){
				ObjectDrawServer.getInstance().moveObject(Integer.parseInt(args[0])-x,Integer.parseInt(args[1])-y);
			}
		}
	}

}
